import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:largefriends/res/lf_double_ext.dart';
import 'package:largefriends/res/lf_text_style.dart';

import '../res.dart';
import '../res/lf_color.dart';
import '../res/lf_fonts.dart';
import 'keyboard_height.dart';

class LfTextLabelFiled extends StatefulWidget {
  final TextEditingController textEditingController;
  final ValueChanged<String>? onChanged;
  final bool isPassword;
  final TextInputAction? textInputAction;
  final FocusNode? focusNode;
  final int? minLine;
  final int? maxLine;
  final double borderRadius;
  final TextStyle? inputStyle;
  final TextStyle? hintStyle;
  final String hintText;
  final List<TextInputFormatter>? inputFormatters;
  final TextInputType? keyboardType;
  final bool? enable;
  final Widget? prefixIcon;

  const LfTextLabelFiled(
      {super.key,
      required this.textEditingController,
      this.onChanged,
      required this.isPassword,
      this.textInputAction,
      this.focusNode,
      this.minLine,
      this.maxLine,
      this.inputStyle,
      this.hintStyle,
      this.borderRadius = 5,
      required this.hintText,
      this.inputFormatters,
      this.keyboardType,
      this.enable = true,
      this.prefixIcon});

  @override
  State<LfTextLabelFiled> createState() => _LfTextFiledState();
}

class _LfTextFiledState extends State<LfTextLabelFiled> with
    WidgetsBindingObserver,
    KeyboardHeight,
    SingleTickerProviderStateMixin{
  bool showPassword = false;
  @override
  Widget build(BuildContext context) {
    return TextField(
      autofocus: false,
      enabled: widget.enable,
      inputFormatters: widget.inputFormatters,
      style: widget.inputStyle ??
          lfTextStyle(sp: 14.sp, fontFamily: fontRegular, color: colorFEFEFE),
      cursorColor: colorFEFEFE,
      keyboardType: widget.keyboardType,
      focusNode: widget.focusNode,
      obscureText: widget.isPassword && !showPassword,
      controller: widget.textEditingController,
      onChanged: widget.onChanged,
      textInputAction: widget.textInputAction,
      maxLines: widget.maxLine ?? 1,
      minLines: widget.minLine ?? 1,
      decoration: InputDecoration(
          isCollapsed: true,
          filled: true,
          fillColor: color8F8F8F,
          // hintText: widget.hintText,
          labelText: widget.hintText,
          labelStyle: lfHintStyle,
          hintStyle: widget.hintStyle ?? lfHintStyle,
          contentPadding:
              EdgeInsets.symmetric(vertical: 12.h, horizontal: 18.w),
          prefixIcon: widget.prefixIcon,
          suffixIcon: widget.isPassword
              ? InkWell(
                  splashColor: Colors.transparent,
                  highlightColor: Colors.transparent,
                  onTap: () {
                    setState(() {
                      showPassword = !showPassword;
                    });
                  },
            ///TODO
                  child: Container(
                    height: 40.r,
                    width: 40.r,
                    alignment: Alignment.center,
                    child: Image.asset(!showPassword
                        ? Res.login_eye_close
                        : Res.login_eye_open,color:colorFEFEFE,width: 20.r,height: 20.r,),
                  ),
                )
              : const SizedBox.shrink(),
          focusedBorder: OutlineInputBorder(
              borderRadius: 40.r.radius,
              borderSide: BorderSide(color: Colors.transparent, width: 1.r)),
          enabledBorder: OutlineInputBorder(
              borderRadius: 40.r.radius,
              borderSide: BorderSide(color: Colors.transparent, width: 1.r)),
          disabledBorder: OutlineInputBorder(
              borderRadius: 40.r.radius,
              borderSide: BorderSide(color: Colors.transparent, width: 1.r)),
          border: OutlineInputBorder(
              borderRadius: 40.r.radius,
              borderSide: BorderSide(color: Colors.transparent, width: 1.r))),
    );
  }
}
